<template>
	<view class="evaluate">
		<!-- 遍历评论列表 -->
		<view v-for="(item, index) in list" :key="index" class="comment-item">
			<!-- 显示评论内容 -->
			<view class="comment-content">{{ item.content }}</view>
			<!-- 显示格式化后的日期 -->
			<view class="comment-date">{{ formatDate(item.date) }}</view>
		</view>
	</view>
</template>

<script>
import { evaluateList } from '../../../common/api'

export default {
	data() {
		return {
			id: null,
			list: [],
		}
	},
	onLoad(o) {
		console.log(o.id, 111);
		this.id = o.id
		this.comments()
	},
	methods: {
		async comments() {
			let res = await evaluateList(this.id)
			console.log(res, 222);
			this.list = res
		},
		// 日期格式化方法
		formatDate() {
			const date = new Date();
			const year = date.getFullYear();
			const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始‌:ml-citation{ref="1,4" data="citationList"}
			const day = String(date.getDate()).padStart(2, '0');
			const hours = String(date.getHours()).padStart(2, '0');
			const minutes = String(date.getMinutes()).padStart(2, '0');
			const seconds = String(date.getSeconds()).padStart(2, '0');
			return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		}
	}
}
</script>

<style lang="scss" scoped>
.evaluate {
	padding: 32rpx;
}
.comment-item {
	margin-bottom: 15px;
	border-bottom: 1px solid #eee;
	padding-bottom: 15px;
}

.comment-content {
	font-size: 16px;
	color: #333;
}

.comment-date {
	font-size: 12px;
	color: #999;
	margin-top: 5px;
}
</style>
